package com.csdj.controller.sy;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.csdj.common.utils.ResponseResult;
import com.csdj.pojo.SyMetertype;
import com.csdj.service.SyMetertypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 涵哥
 * @date 2023-08-24 16:16
 *     水表型号
 */
@RestController
@RequestMapping("/sy/MeterType")
public class SystemMeterTypeController {
    @Autowired
    private SyMetertypeService syMetertypeService;

    /**
     * 水表型号的列表
     * @return
     */
    @GetMapping
    public ResponseResult list(){
        List<SyMetertype> list = syMetertypeService.list(Wrappers.<SyMetertype>lambdaQuery().eq(SyMetertype::getDisabled,0).orderByDesc(SyMetertype::getId));
        return ResponseResult.okResult(list);
    }

    /**
     * 新增
     * @param syMetertype
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody SyMetertype syMetertype){
        syMetertype.setDisabled(0);
        return ResponseResult.okResult(syMetertypeService.save(syMetertype));
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult remove(@PathVariable Integer id){
        return ResponseResult.okResult(syMetertypeService.removeById(id));
    }

    /**
     * 根据id查找
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResponseResult getOne(@PathVariable Integer id){
        return ResponseResult.okResult(syMetertypeService.getById(id));
    }

    /**
     * 修改
     * @param syMetertype
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody SyMetertype syMetertype){
        return ResponseResult.okResult(syMetertypeService.updateById(syMetertype));
    }
}
